package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");//不同数据库的包名.类名不一样，但是对于同一个数据库无论那个版本写法都是一致的。
        try (
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root");
        ) {
            Statement statement = conn.createStatement();
            String sql = "CREATE TABLE student1(" +
                            "       id INT primary key auto_increment," +
                            "       name VARCHAR(30) NOT NULL ," +
                            "       age INT(3)," +
                            "       class_id INT" +
                            "     )";
//            String sql = "CREATE TABLE class(" +
//                    "       id INT primary key auto_increment," +
//                    "       name VARCHAR(30) NOT NULL" +
//                    "     )";
            statement.execute(sql);
            System.out.println("执行完毕!");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}